<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\CountryController;
use App\Http\Controllers\LanguageController;
use App\Http\Controllers\LocaleController;
use App\Http\Controllers\RegionController;
use App\Http\Controllers\DistrictController;
use App\Http\Controllers\CityController;
use App\Http\Controllers\ZipcodeController;
use App\Http\Controllers\PersonController;
use App\Http\Controllers\CompanyController;
use App\Http\Controllers\TypeController;
use App\Http\Controllers\AddressController;
use App\Http\Controllers\TelephoneController;
use App\Http\Controllers\EmailController;
use App\Http\Controllers\PictureController;

$prefix = '/v1/';

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Public routes
Route::group(
  [
    'prefix' => $prefix,
    'headers' => ['Content-Type' => 'application/json'],
    'middleware' => ['localization'],
  ],
  function () {
    Route::post('/register', [AuthController::class, 'register']);
    Route::post('/login', [AuthController::class, 'login']);
    Route::get('/locales', [LocaleController::class, 'index']);
  }
);

// Protected routes
Route::group(
  [
    'prefix' => $prefix,
    'headers' => ['Content-Type' => 'application/json'],
    'middleware' => ['auth:sanctum', 'localization']
  ],
  function () {
    // Auth routes
    Route::get('/activate', [AuthController::class, 'activate']);
    Route::get('/logout', [AuthController::class, 'logout']);
    Route::get('/authenticatedUser', [AuthController::class, 'authenticatedUser']);
    // User routes
    Route::get('/users', [UserController::class, 'index']);
    Route::post('/users', [UserController::class, 'store']);
    Route::get('/users/{id}', [UserController::class, 'show']);
    Route::put('/users/{id}', [UserController::class, 'update']);
    Route::delete('/users/{id}', [UserController::class, 'destroy']);
    // Role routes
    Route::get('/roles', [RoleController::class, 'index']);
    Route::post('/roles', [RoleController::class, 'store']);
    Route::get('/roles/{id}', [RoleController::class, 'show']);
    Route::put('/roles/{id}', [RoleController::class, 'update']);
    Route::delete('/roles/{id}', [RoleController::class, 'destroy']);
    // Permission routes
    Route::get('/permissions', [PermissionController::class, 'index']);
    Route::post('/permissions', [PermissionController::class, 'store']);
    Route::get('/permissions/{id}', [PermissionController::class, 'show']);
    Route::put('/permissions/{id}', [PermissionController::class, 'update']);
    Route::delete('/permissions/{id}', [PermissionController::class, 'destroy']);
    // Country routes
    Route::get('/countries', [CountryController::class, 'index']);
    Route::post('/countries', [CountryController::class, 'store']);
    Route::get('/countries/{id}', [CountryController::class, 'show']);
    Route::put('/countries/{id}', [CountryController::class, 'update']);
    Route::delete('/countries/{id}', [CountryController::class, 'destroy']);
    // Language routes
    Route::get('/languages', [LanguageController::class, 'index']);
    Route::post('/languages', [LanguageController::class, 'store']);
    Route::get('/languages/{id}', [LanguageController::class, 'show']);
    Route::put('/languages/{id}', [LanguageController::class, 'update']);
    Route::delete('/languages/{id}', [LanguageController::class, 'destroy']);
    // Locale routes
    // Route::get('/locales', [LocaleController::class, 'index']);
    Route::post('/locales', [LocaleController::class, 'store']);
    Route::get('/locales/{id}', [LocaleController::class, 'show']);
    Route::put('/locales/{id}', [LocaleController::class, 'update']);
    Route::delete('/locales/{id}', [LocaleController::class, 'destroy']);
    // Region routes
    Route::get('/regions', [RegionController::class, 'index']);
    Route::post('/regions', [RegionController::class, 'store']);
    Route::get('/regions/{id}', [RegionController::class, 'show']);
    Route::put('/regions/{id}', [RegionController::class, 'update']);
    Route::delete('/regions/{id}', [RegionController::class, 'destroy']);
    // District routes
    Route::get('/districts', [DistrictController::class, 'index']);
    Route::post('/districts', [DistrictController::class, 'store']);
    Route::get('/districts/{id}', [DistrictController::class, 'show']);
    Route::put('/districts/{id}', [DistrictController::class, 'update']);
    Route::delete('/districts/{id}', [DistrictController::class, 'destroy']);
    // City routes
    Route::get('/cities', [CityController::class, 'index']);
    Route::post('/cities', [CityController::class, 'store']);
    Route::get('/cities/{id}', [CityController::class, 'show']);
    Route::put('/cities/{id}', [CityController::class, 'update']);
    Route::delete('/cities/{id}', [CityController::class, 'destroy']);
    // Zipcode routes
    Route::get('/zipcodes', [ZipcodeController::class, 'index']);
    Route::post('/zipcodes', [ZipcodeController::class, 'store']);
    Route::get('/zipcodes/{id}', [ZipcodeController::class, 'show']);
    Route::put('/zipcodes/{id}', [ZipcodeController::class, 'update']);
    Route::delete('/zipcodes/{id}', [ZipcodeController::class, 'destroy']);
    // Person routes
    Route::get('/people', [PersonController::class, 'index']);
    Route::post('/people', [PersonController::class, 'store']);
    Route::get('/people/{id}', [PersonController::class, 'show']);
    Route::put('/people/{id}', [PersonController::class, 'update']);
    Route::delete('/people/{id}', [PersonController::class, 'destroy']);
    // Company routes
    Route::get('/companies', [CompanyController::class, 'index']);
    Route::post('/companies', [CompanyController::class, 'store']);
    Route::get('/companies/{id}', [CompanyController::class, 'show']);
    Route::put('/companies/{id}', [CompanyController::class, 'update']);
    Route::delete('/companies/{id}', [CompanyController::class, 'destroy']);
    // Type routes
    Route::get('/types', [TypeController::class, 'index']);
    Route::post('/types', [TypeController::class, 'store']);
    Route::get('/types/{id}', [TypeController::class, 'show']);
    Route::put('/types/{id}', [TypeController::class, 'update']);
    Route::delete('/types/{id}', [TypeController::class, 'destroy']);
    // Address routes
    Route::get('/addresses', [AddressController::class, 'index']);
    Route::post('/addresses', [AddressController::class, 'store']);
    Route::get('/addresses/{id}', [AddressController::class, 'show']);
    Route::put('/addresses/{id}', [AddressController::class, 'update']);
    Route::delete('/addresses/{id}', [AddressController::class, 'destroy']);
    // Telephone routes
    Route::get('/telephones', [TelephoneController::class, 'index']);
    Route::post('/telephones', [TelephoneController::class, 'store']);
    Route::get('/telephones/{id}', [TelephoneController::class, 'show']);
    Route::put('/telephones/{id}', [TelephoneController::class, 'update']);
    Route::delete('/telephones/{id}', [TelephoneController::class, 'destroy']);
    // Email routes
    Route::get('/emails', [EmailController::class, 'index']);
    Route::post('/emails', [EmailController::class, 'store']);
    Route::get('/emails/{id}', [EmailController::class, 'show']);
    Route::put('/emails/{id}', [EmailController::class, 'update']);
    Route::delete('/emails/{id}', [EmailController::class, 'destroy']);
    // Picture routes
    Route::get('/pictures', [PictureController::class, 'index']);
    Route::post('/pictures', [PictureController::class, 'store']);
    Route::get('/pictures/{id}', [PictureController::class, 'show']);
    Route::put('/pictures/{id}', [PictureController::class, 'update']);
    Route::delete('/pictures/{id}', [PictureController::class, 'destroy']);
    Route::get('/pictures/download/{id}', [PictureController::class, 'download']);
  }
);
